package com.ifast.wxmp.controller;


import java.util.Arrays;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ifast.common.base.AdminBaseController;
import com.ifast.wxmp.domain.MpArticleDO;
import com.ifast.wxmp.service.MpArticleService;
import com.ifast.common.utils.Result;

/**
 * 
 * <pre>
 * 微信文章表
 * </pre>
 * <small> 2019-02-13 16:22:52 | houzw</small>
 */
@SuppressWarnings("unused")
@Controller
@RequestMapping("/wxmp/mpArticle")
public class MpArticleController extends AdminBaseController {
	@Autowired
	private MpArticleService mpArticleService;
	
	@GetMapping()
	//@RequiresPermissions("wxmp:mpArticle:mpArticle")
	String MpArticle(){
	    return "wxmp/mpArticle/mpArticle";
	}
	// -------------------------------公众号页面接口开始---------------------------
	@GetMapping("/wx")
	String wx(){
	    return "wxmp/wx/mpArticle/mpArticle";
	}
	// -------------------------------公众号页面接口结束---------------------------
	@ResponseBody
	@GetMapping("/list")
	//@RequiresPermissions("wxmp:mpArticle:mpArticle")
	public Result<Page<MpArticleDO>> list(MpArticleDO mpArticleDTO){
        Wrapper<MpArticleDO> wrapper = new EntityWrapper<MpArticleDO>(mpArticleDTO);
        Page<MpArticleDO> page = mpArticleService.selectPage(getPage(MpArticleDO.class), wrapper);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	//@RequiresPermissions("wxmp:mpArticle:add")
	String add(){
	    return "wxmp/mpArticle/add";
	}

	@GetMapping("/edit/{id}")
	//@RequiresPermissions("wxmp:mpArticle:edit")
	String edit(@PathVariable("id") Long id,Model model){
		MpArticleDO mpArticle = mpArticleService.selectById(id);
		model.addAttribute("mpArticle", mpArticle);
	    return "wxmp/mpArticle/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	//@RequiresPermissions("wxmp:mpArticle:add")
	public Result<String> save( MpArticleDO mpArticle){
		mpArticleService.insert(mpArticle);
        return Result.ok();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	//@RequiresPermissions("wxmp:mpArticle:edit")
	public Result<String>  update( MpArticleDO mpArticle){
		mpArticleService.updateById(mpArticle);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	//@RequiresPermissions("wxmp:mpArticle:remove")
	public Result<String>  remove( Long id){
		mpArticleService.deleteById(id);
        return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	//@RequiresPermissions("wxmp:mpArticle:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		mpArticleService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
